tpm2: Resolve a few issues detected with gcc -fanalyzer#552
Merged
stefanberger merged 7 commits intomasterfrom Feb 11, 2026
Merged
tpm2: Resolve a few issues detected with gcc -fanalyzer#552stefanberger merged 7 commits intomasterfrom
stefanberger merged 7 commits intomasterfrom
Conversation
gcc's -fanalyzer claims that strtoul() may be called with str == NULL. However, this cannot happen since in this case retVal would have been set from the call to RuntimeProfileGetFromJSON(). In case of error returned from RuntimeProfileGetFromJSON() we would not get to call strtoul(). So this is a false-positive. Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Resolve the following gcc -fanalyzer issue by casting the result of
sizeof() to uint32_t.
tpm12/tpm_cryptoh.c:977:16: warning: 'va_arg' expected 'uint32_t' \
{aka 'unsigned int'} but received 'long unsigned int' \
for variadic argument 3 of 'ap' [CWE-686] [-Wanalyzer-va-arg-type-mismatch]
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Resolve the following gcc -fanalyzer issue by initializing the variable.
tpm12/tpm_migration.c: In function 'TPM_Process_CMK_CreateBlob':
tpm12/tpm_migration.c:3389:10: warning: use of uninitialized value
'continueAuthSession' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
3389 | !continueAuthSession) &&
| ^~~~~~~~~~~~~~~~~~~~
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Resolve the following issues detected by gcc's -fanalyzer:
tpm12/tpm_session.c: In function 'TPM_AuthSessionData_Store':
tpm12/tpm_session.c:187:65: warning: dereference of NULL 'tpm_auth_session_data' [CWE-476] [-Wanalyzer-null-dereference]
187 | rc = TPM_Sbuffer_Append32(sbuffer, tpm_auth_session_data->handle);
tpm12/tpm_session.c: In function 'TPM_Process_SaveContext':
tpm12/tpm_session.c:3197:41: warning: use of uninitialized value 'tpm_key_handle_entry' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
3197 | if (tpm_key_handle_entry->keyControl & TPM_KEY_CONTROL_OWNER_EVICT) {
tpm12/tpm_session.c:3230:26: warning: use of uninitialized value 'tpm_key_handle_entry' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
3230 | returnCode = TPM_KeyHandleEntry_Store(&r1ContextSensitive, tpm_key_handle_entry);
tpm12/tpm_session.c:3236:26: warning: use of uninitialized value 'tpm_transport_internal' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
3236 | returnCode = TPM_TransportInternal_Store(&r1ContextSensitive, tpm_transport_internal);
tpm12/tpm_session.c:3239:26: warning: use of uninitialized value 'tpm_daa_session_data' [CWE-457] [-Wanalyzer-use-of-uninitialized-value]
3239 | returnCode = TPM_DaaSessionData_Store(&r1ContextSensitive, tpm_daa_session_data);
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Resolve the following issues detected by gcc's -fanalyzer:
tpm12/tpm_counter.c: In function 'TPM_CounterValue_StorePublic.part.0':
tpm12/tpm_counter.c:421:61: warning: dereference of NULL 'tpm_counter_value' [CWE-476] [-Wanalyzer-null-dereference]
421 | rc = TPM_Sbuffer_Append32(sbuffer, tpm_counter_value->counter);
| ~~~~~~~~~~~~~~~~~^~~~~~~~~
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Resolve the following issues detected by gcc's -fanalyzer:
tpm12/tpm_nvram.c: In function 'TPM_Process_NVDefineSpace':
tpm12/tpm_nvram.c:2908:20: warning: dereference of NULL 'd1_new' [CWE-476] [-Wanalyzer-null-dereference]
2908 | newNVIndex = pubInfo->nvIndex; /* save the possibly new index */
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
146cc2f to
3bdb4f0
Compare
Check that the object returned from HandleToObject is not NULL before dereferencing it. In practice, this cannot currently happen in the call paths that GetHierachy() is called because the object described by the handle is known to exist. Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TPM 2 code: gcc's -fanalyzer claims that strtoul() may be called with str == NULL. However, this cannot happen since in this case retVal would have been set from the call to RuntimeProfileGetFromJSON(). In case of error returned from RuntimeProfileGetFromJSON() we would not get to call strtoul(). So this is a false-positive.
TPM 1.2 code: simply initialize some variable or intercept NULL pointers where -fanalyzer complains.